﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Adapters;

// change to your own custom component namespace.
namespace MoonDust
{
    

    [ToolboxData("<asp:ActiveMenu runat=server></asp:ActiveMenu>")]
    public class ActiveMenu : Menu
    {
        // the menu works - just needs tweaking.
        public ActiveMenu(): base()
        {
            // do nothing in the constructor.
        }

        private const string ClassSupportScript = "<style type=\"text/css\">.ActiveMenuStyle{z-index: 100;}.ActiveMenuItemStyle a{width:100%;display:block;}</style>";

        protected override void OnPreRender(EventArgs e)
        {
            //override the rendering of the css class if the cssclass is not present
            //if cssclass is present lets hope they set the z-index in the their style sheet
            if (DynamicMenuStyle.CssClass == "")
                DynamicMenuStyle.CssClass = "ActiveMenuStyle";

            if (DynamicMenuItemStyle.CssClass == "")
                DynamicMenuItemStyle.CssClass = "ActiveMenuItemStyle";

            if (StaticMenuStyle.CssClass == "")
                StaticMenuStyle.CssClass = "ActiveMenuStyle";

            if (StaticMenuItemStyle.CssClass == "")
                StaticMenuItemStyle.CssClass = "ActiveMenuItemStyle";

            // call the base style render
            base.OnPreRender(e);

            // write this style tag only once on the page
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ActiveMenuStyleBlock", ClassSupportScript);

        }

        

        protected override System.Web.UI.Adapters.ControlAdapter ResolveAdapter()
        {
            // just assume the browser is modern. resolves firefox, crome, safari 
            // not the best idea for old browsers - tough cookies 
            return null;
        }

    }
}
